<?php
/**
 * Created by PhpStorm.
 * User: administrator
 * Date: 2016/9/2 0002
 * Time: 10:12
 */

namespace Home\Controller;
use Think\Controller;
 
//用户中心全局控制
class LogisticsController extends  Controller{ 
    
    public function info(){
    	
    	//物流单号
    	$code = I('request.code','','trim'); 
    	//类文件
    	$cls = I('request.ac','','trim');
    	
    	
    	if(empty($code)){
    	     $this->error("物流单号为空");    		
    	}
    	
    	if(empty($cls)){
    		$this->error("参数错误");
    	} 
    	 
        $dbprefix=C('DB_PREFIX');
    	$list= M("order_info")->field("o.order_id AS orderid,o.order_sn AS ordercode,o.org_order_sn AS org_ordercode,c.name AS companyname,b.`group_name`,c.weburl,b.`configurl`,d.invoice_no AS invoicecode,FROM_UNIXTIME(d.`add_time`,'%Y-%m-%d %H:%i:%s') AS add_time")
    	->alias("o")->join(" inner join ".$dbprefix."delivery_order d ON o.order_id=d.order_id")
    	->join(" inner join ".$dbprefix."expresscompany c ON c.id= d.expresscompany_id")
    	->join(" inner join ".$dbprefix."expresscompany_group b ON c.exp_gronp_id=b.id")->where("d.invoice_no='$code'")->find(); 
       
        if(!$list || count($list)==0){  
    		 $this->error("请确认是否已经发送物流货运");    
    	}  

    	//物流数据处理
    	$FILEPATH= APP_PATH.'Common/Api/'.strtolower($cls).".class.php";
    	if(!file_exists($FILEPATH)){
    		 $this->error("非合作物流公司");   
    	}
    	
    	
    	$ary=array('code'=>$code);    	
    	
    	require_once($FILEPATH);
    	$clsname='\\Common\\Api\\'.$cls;
    	$sc = new $clsname();
    	$jsondata= $sc->postservice($ary); 
    	
    	if(empty($jsondata)){
    		$this->error("获取物流信息为空");
    	}
    	
    	//$arydata= json_decode($jsondata,true);
    	if(!is_array($jsondata)){
    		$this->error("获取物流信息失败");
    	}
    	
    	if($jsondata['error']!="0"){
    		$this->error($jsondata['errmsg']);
    	}
    	$lst= $jsondata['rows']; 
    	$this->assign("list",$lst);
    	$this->assign("item",$list); 
    	$this->display();
    } 





}